package com.hht.study.limit.aop;

import com.hht.study.limit.anno.Limit;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author hht
 * @date 2022/3/11
 */
@Aspect
@Configuration
public class LimitAspect {

    @Around("@annotation(com.hht.study.limit.anno.Limit)")
    public Object handle(ProceedingJoinPoint joinPoint){
        MethodSignature methodSignature = (MethodSignature)joinPoint.getSignature();
        Method method = methodSignature.getMethod();
        Limit annotation = method.getAnnotation(Limit.class);
        String key = annotation.key();
        String prefix = annotation.prefix();
        String keyPath=prefix+key;

        int limitCount = annotation.count();
        int period = annotation.period();

        return null;
    }

    public String buildLuaScript(){
        StringBuilder sb=new StringBuilder();
        sb.append("");
        return sb.toString();
    }
}
